
from flask_sqlalchemy import SQLAlchemy
from flask import current_app, request
from flask_login import UserMixin, AnonymousUserMixin
from werkzeug.security import generate_password_hash, check_password_hash

from . import login_manager

# import sys
#
# sys.path.append('.')
# sys.path.append('..')

from src.app import db, elineStat, eTeachOption


# 学校表
'''
表名：school
字段：id，主键。char(64)----------主键
    name 学校名称 char(64)
    addr 学校地址 char(64)
    phone 学校电话 char(16)
    fox 学校传真 char(16)
    homepage 学校主页 char(255)
    logo 学校图标url char(255)
    disc 学校描述 text
'''
class tSchool(db.Model):
    __tablename__ = 'school'

    id = db.Column(db.String(64), primary_key=True)
    name = db.Column(db.String(64))
    addr = db.Column(db.String(64))
    phone = db.Column(db.String(16))
    fox = db.Column(db.String(16))
    homepage = db.Column(db.String(255))
    logo = db.Column(db.String(255))
    disc = db.Column(db.Text)
    flag = db.Column(db.Integer, default=elineStat.enable)  # 1:启用，0：禁用，2，待审核,3、拒绝

    # colleges = db.relationship('college', backref='colleges_id')

    def __repr__(self):
        return '<school %r>' % self.name


# 学院表
'''
表名 college
字段：id，主键。char(64)----------主键
    name 学院名称 char(64)
    createtime 创建时间 datetime
    shoolId 学校id char(64)----------外键school.id
    flag 启用标识 integer 可选范围：elineStat
'''
class tCollege(db.Model):
    __tablename__ = 'college'

    id = db.Column(db.String(64), primary_key=True)
    name = db.Column(db.String(64), nullable=False)
    createtime = db.Column(db.DateTime)
    schoold = db.Column(db.String(64), db.ForeignKey('school.id'))
    flag = db.Column(db.Integer, default=elineStat.enable)  # 1:启用，0：禁用，2，待审核

    # majors = db.relationship('major', backref='major_id')

    def __repr__(self):
        return '<college %r>' % self.name


# 专业表
'''
表名 major
字段：id，主键。char(64)----------主键
    name 专业名称 char(64)
    createtime 创建时间 datetime
    collegeid 学院id char(64)----------外键college.id
    flag 启用标识 integer 可选范围：elineStat
'''
class tMajor(db.Model):
    __tablename__ = 'major'

    id = db.Column(db.String(64), primary_key=True)
    name = db.Column(db.String(64), nullable=False)
    createtime = db.Column(db.DateTime)
    collegeid = db.Column(db.String(64), db.ForeignKey('college.id'))
    flag = db.Column(db.Integer, default=elineStat.enable)  # 1:启用，0：禁用，2，待审核

    # clazzes = db.relationship('clazz', backref='clazzes_id')

    def __repr__(self):
        return '<major %r>' % self.name


# 班级表
'''
表名 clazz
字段：id，主键。char(64)----------主键
    name 班级名称 char(64)
    createtime 创建时间 datetime
    majorid 专业id char(64)----------外键major.id
    flag 启用标识 integer 可选范围：elineStat
'''
class tClazz(db.Model):
    __tablename__ = 'clazz'

    id = db.Column(db.String(64), primary_key=True)
    name = db.Column(db.String(64))
    createtime = db.Column(db.DateTime)
    majorid = db.Column(db.String(64), db.ForeignKey('major.id'))

    # map_studclazzes = db.relationship('map_studclazz', backref='map_studinclazzes')
    # map_teach = db.relationship('map_teach', backref='map_teacherinclazzes')
    flag = db.Column(db.Integer, default=elineStat.enable)  # 1:启用，0：禁用，2，待审核

    def __repr__(self):
        return '<clazz %r>' % self.name


# 角色表
'''
表名 role
字段：id，主键。char(64)----------主键
    name 角色名称 char(64)
    createtime 创建时间 datetime
    flag 启用标识 integer 可选范围：elineStat
'''
class tRole(db.Model):
    __tablename__ = 'role'

    id = db.Column(db.String(64), primary_key=True)
    name = db.Column(db.String(64), nullable=False)
    createtime = db.Column(db.DateTime)
    flag = db.Column(db.Integer, default=elineStat.enable)

    # users = db.relationship('alluser', backref='users')

    def __repr__(self):
        return '<role %r>' % self.name


# 用户表
'''
表名 alluser
字段：id，主键。char(64)----------主键
    name 用户名 char(64)
    password_hash 用户密码hash值
    createtime 创建时间 datetime
    flag 启用标识 integer 可选范围：elineStat
    roleid 角色id char(64)-------------外键 role.id
'''


class tAllUser(db.Model):
    __tablename__ = 'alluser'

    id = db.Column(db.String(64), primary_key=True)
    name = db.Column(db.String(64))
    password_hash = db.Column(db.String(128))
    createtime = db.Column(db.DateTime)
    flag = db.Column(db.Integer, default=elineStat.enable)  # 1:启用，0：禁用，2，待审核

    roleid = db.Column(db.String(64), db.ForeignKey('role.id'))

    # map_studclazzes = db.relationship('map_studclazz', backref='map_studclazzes')
    # map_teach = db.relationship('map_teach', backref='map_teacherinalluser')
    # createteachers = db.relationship('match', backref='createteachers')
    # players = db.relationship('player', backref='playersinalluser')
    # judgers = db.relationship('judger', backref='judgersinalluser')

    # courselogs = db.relationship('courselog', backref='alluser')
    # matchlogs = db.relationship('matchlog', backref='alluser')
    # matchlogs = db.relationship('matchlog', backref='alluser')
    # courselogs_stuid = db.relationship('courselog', foreign_keys=[tCourselog.studid],
    #                                    backref=db.backref('courselogs_studid'),
    #                                    cascade='all,delete-orphan')
    # courselogs_teacherid = db.relationship('courselog', foreign_keys=[tCourselog.teacherid],
    #                                        backref=db.backref('courselogs_teacherid'),
    #                                        cascade='all,delete-orphan')
    # matchlogs_stuid = db.relationship('matchlog', foreign_keys=[tMatchlog.studid],
    #                                   backref=db.backref('matchlogs_stuid'),
    #                                   cascade='all,delete-orphan')
    # matchlogs_teacherid = db.relationship('matchlog', foreign_keys=[tMatchlog.studid],
    #                                       backref=db.backref('matchlogs_teacherid', ),
    #                                       cascade='all,delete-orphan')
    # matchlogs_judgerid = db.relationship('matchlog', foreign_keys=[tMatchlog.studid],
    #                                      backref=db.backref('matchlogs_judgerid', ),
    #                                      cascade='all,delete-orphan')

    def __repr__(self):
        return '<alluser %r>' % self.name

    @property
    def password(self):
        raise AttributeError('密码不能直接访问！')

    @password.setter
    def passwd(self, password):
        self.password_hash = generate_password_hash(password)

    def verify_password(self, password):
        return check_password_hash(password)

    def None_Password(self):
        if self.password_hash is None:
            return True

    @login_manager.user_loader
    def load_user(self, user_id):
        tAllUser.query.get(user_id)


# 路径表
'''
表名 tPath
字段：id，主键。char(64)----------主键
    name 路径名称 char(64)
    createtime 创建时间 datetime
    modiftime 最后修改时间 datetime
    flag 启用标识 integer 可选范围elineStat
    teahoption 提交操作 integer 可选范围：eTeachOption
    adminoption 审批操作 integer 可选范围：eAdminOption
    oldID 旧关系对应本表的关系 char(64)
'''


class tPath(db.Model):
    __tablename__ = 'path'

    id = db.Column(db.String(64), primary_key=True)
    name = db.Column(db.String(64))
    logo = db.Column(db.String(255))
    createtime = db.Column(db.DateTime)
    modiftime = db.Column(db.DateTime)
    flag = db.Column(db.Integer, default=elineStat.examine)  # 1:启用，0：禁用，2，待审核
    teahoption = db.Column(db.Integer)  # 1:添加，2：删除
    adminoption = db.Column(db.Integer)  #
    oldID = db.Column(db.String(64), default=None)
    # pathstep = db.relationship('pathstep', backref='pathstep_id')

    def __repr__(self):
        return '<path %r>' % self.name


# 路径阶段表
'''
表名 tPathStep
字段：id，主键。char(64)----------主键
    name 路径阶段名称 char(64)
    createtime 创建时间 datetime
    modiftime 最后修改时间 datetime
    level 阶段顺序 integer
    pathid 学习路径id char(64)------------------外键 path.id
    flag 启用标识 integer 可选范围：elineStat
    teahoption 提交操作 integer 可选范围：eTeachOption
    adminoption 审批操作 integer 可选范围：eAdminOption
    oldID 旧关系对应本表的关系 char(64)
'''


class tPathStep(db.Model):
    __tablename__ = 'pathstep'

    id = db.Column(db.String(64), primary_key=True)
    name = db.Column(db.String(64))
    createtime = db.Column(db.DateTime)
    modiftime = db.Column(db.DateTime)
    level = db.Column(db.Integer)
    pathid = db.Column(db.String(64), db.ForeignKey('path.id'))
    flag = db.Column(db.Integer, default=elineStat.examine)  # 1:启用，0：禁用，2，待审核
    teahoption = db.Column(db.Integer)  # 1：添加，2：删除
    adminoption = db.Column(db.Integer)
    oldID = db.Column(db.String(64), default=None)
    # map_coursetopathstepid = db.relationship('map_coursetopathstep', backref='map_coursetopathstepidinstep')

    def __repr__(self):
        return '<pathstep %r>' % self.name


# 课程表
'''
表名 course
字段：id，主键。char(64)----------主键
    name 课程名称 char(64)
    createtime 创建时间 datetime
    modiftime 最后修改时间 datetime
    disc 课程描述 text
    logo 图片url char(255)
    flag 启用标识 integer 可选范围：elineStat
    teahoption 提交操作 integer 可选范围：eTeachOption
    adminoption 审批操作 integer 可选范围：eAdminOption
    oldID 修改用，已存在相同课程的id 默认值none为新课程
'''
class tCourse(db.Model):
    __tablename__ = 'course'

    id = db.Column(db.String(64), primary_key=True)
    name = db.Column(db.String(64))
    createtime = db.Column(db.DateTime)
    modiftime = db.Column(db.DateTime)
    disc = db.Column(db.Text)
    logo = db.Column(db.String(255))
    flag = db.Column(db.Integer, default=elineStat.examine)  # 1:启用，0：禁用，2，待审核
    teahoption = db.Column(db.Integer)  # 1：添加，2：删除
    adminoption = db.Column(db.Integer)
    oldID = db.Column(db.String(64), default=None)


    # map_teach = db.relationship('map_teach', backref='map_teach')
    # map_coursetopathstepid = db.relationship('map_coursetopathstep', backref='map_coursetopathstepidincourse')

    def __repr__(self):
        return '<course %r>' % self.name


# 学生班级关系表
'''
表名 map_studclazz
字段：id，主键。char(64)----------主键
    stuid 学生id char(64)-----------------外键alluser.id
    clazzid 班级id char(64) ---------------外键 clazz.id
    flag 启用标识 integer 可选范围：elineStat
'''


class tMap_studclazz(db.Model):
    __tablename__ = 'map_studclazz'

    id = db.Column(db.String(64), primary_key=True)
    studid = db.Column(db.String(64), db.ForeignKey('alluser.id'))
    clazzid = db.Column(db.String(64), db.ForeignKey('clazz.id'))
    flag = db.Column(db.Integer, default=elineStat.enable)  # 1:启用，0：禁用，2，待审核
    oldid = db.Column(db.String(64), default=None)

    def __repr__(self):
        return '<map_studclazz %r>' % self.id


# 章节/笔记表
'''
表名 caption
字段：id，主键。char(64)----------主键
    name 章节名称 char(64)
    courseid 课程id char(64) ---------------外键 course.id
    createtime 创建时间 datetime
    modiftime 最后修改时间 datetime
    disc 课程描述 text
    modelid 模板id char(64) -----------------外键 captionmodel.id
    level 章节顺序 integer
    flag 启用标识 integer 可选范围：elineStat
    teahoption 提交操作 integer 可选范围：eTeachOption
    adminoption 审批操作 integer 可选范围：eAdminOption
    oldID 旧关系对应本表的关系 char(64)
'''


class tCaption(db.Model):
    __tablename__ = 'caption'

    id = db.Column(db.String(64), primary_key=True)
    name = db.Column(db.String(64))
    courseid = db.Column(db.String(64), db.ForeignKey('course.id'))
    createtime = db.Column(db.DateTime)
    modeftime = db.Column(db.DateTime)
    disc = db.Column(db.Text)
    modelid = db.Column(db.String(64))
    level = db.Column(db.Integer)
    flag = db.Column(db.Integer, default=elineStat.examine)  # 1:启用，0：禁用，2，待审核
    teahoption = db.Column(db.Integer)  # 1：添加，2：删除
    adminoption = db.Column(db.Integer)
    oldID = db.Column(db.String(64), default=None)

    # matchs = db.relationship('match', backref='matchsmodelid')
    # map_captioncourses = db.relationship('map_captioncourse', backref='map_captioncoursesincaptionmode')

    def __repr__(self):
        return '<caption %r>' % self.name


# # 学习路径-路径阶段关系表
# '''
# 表名 map_pathpathstep
# 字段：id，主键。char(64)----------主键
#     pathid 章节名称 char(64) ---------------外键 path.id
#     pathstepid 课程id char(64) ---------------外键 pathstep.id
#     createtime 创建时间 datetime
#     modiftime 最后修改时间 datetime
#     level 章节顺序 integer
#     flag 启用标识 integer
# '''
# class tMap_PathPathStep(db.Model):
#     __tablename__ = 'map_pathpathstep'
#
#     id = db.Column(db.String(64), primary_key=True)
#
#     pathid = db.Column(db.String(64), db.ForeignKey('path.id'))
#     pathstepid = db.Column(db.String(64), db.ForeignKey('pathstep.id'))
#     createtime = db.Column(db.DateTime)
#     modiftime = db.Column(db.DateTime)
#     level = db.Column(db.Integer)
#     flag = db.Column(db.Integer, default=elineStat.examine)


# 课程-学习路径阶段对应关系
'''
表名 map_coursetopathstep
字段：id，主键。char(64)----------主键
    courseid 课程id char(64)
    pathstepid 路径阶段id char(64)
    createtime 创建时间 datetime
    modiftime 最后修改时间 datetime
    flag 启用标识 integer 可选范围：elineStat
    teahoption 提交操作 integer 可选范围：eTeachOption
    adminoption 审批操作 integer 可选范围：eAdminOption
    oldID 旧关系对应本表的关系 char(64)
'''


class tMap_Course2PathStep(db.Model):
    __tablename__ = 'map_coursetopathstep'

    id = db.Column(db.String(64), primary_key=True)
    courseid = db.Column(db.String(64), db.ForeignKey('course.id'))
    pathstepid = db.Column(db.String(64), db.ForeignKey('pathstep.id'))
    createtime = db.Column(db.DateTime)
    modiftime = db.Column(db.DateTime)
    flag = db.Column(db.Integer, default=elineStat.examine)  # 1:启用，0：禁用，2，待审核
    teahoption = db.Column(db.Integer)  # 1：添加，2：删除
    adminoption = db.Column(db.Integer)
    oldID = db.Column(db.String(64), default=None)

    def __repr__(self):
        return '<map_coursetopathstep %r>' % self.id


# 综合案例表
'''
表名 compcase
字段：id，主键。char(64)----------主键
    name 案例名称 char(64)
    createtime 创建时间 datetime
    disc 案例描述
    logo 图片url char(255)
    modelid 模板id ----------------------外键 captionmodel.id
    pathstepid 学习路径id------------------外键 pathstep,id
    flag 启用标识 integer 可选范围：elineStat
    teahoption 老师操作 integer 可选范围：eTeachOption
    adminoption 审批操作 integer 可选范围：eAdminOption
'''


class tCompCase(db.Model):
    __tablename__ = 'compcase'
    id = db.Column(db.String(64), primary_key=True)
    name = db.Column(db.String(64))
    createtime = db.Column(db.DateTime)
    disc = db.Column(db.TEXT)
    logo = db.Column(db.String(255))
    modelid = db.Column(db.String(64), db.ForeignKey('captionmodel.id'))
    pathstepid = db.Column(db.String(64), db.ForeignKey('pathstep.id'))
    flag = db.Column(db.Integer, default=elineStat.examine)
    teahoption = db.Column(db.Integer)
    adminoption = db.Column(db.Integer)
    oldID = db.Column(db.String(64), default=None)


# 标签表
'''
表名 compcase
字段：id，主键。char(64)----------主键
    name 案例名称 char(64)
    createtime 创建时间 datetime
    flag 启用标识 integer 可选范围：elineStat
    teahoption 老师操作 integer 可选范围：eTeachOption
    adminoption 审批操作 integer 可选范围：eAdminOption
    oldID 旧关系对应本表的关系 char(64)
'''
class tLabel(db.Model):
    __tablename__ = 'label'

    id = db.Column(db.String(64), primary_key=True)
    name = db.Column(db.String(64))
    createtime = db.Column(db.DateTime)
    flag = db.Column(db.Integer, default=elineStat.examine)
    teahoption = db.Column(db.Integer)
    adminoption = db.Column(db.Integer)
    oldID = db.Column(db.String(64), default=None)


# 标签-课程对应表
'''
表名 map_courselabel
字段：id，主键。char(64)----------主键
    name 案例名称 char(64)
    courseid 课程id char(64)--------------外键course.id
    labelid 标签id char(64) --------------外键label.id
    createtime 创建时间 datetime
    flag 启用标识 integer 可选范围：elineStat
    teahoption 老师操作 integer 可选范围：eTeachOption
    adminoption 审批操作 integer 可选范围：eAdminOption
    oldID 修改标签使用但旧标签 char(64)
'''


class tMap_CourseLabel(db.Model):
    __tablename__ = 'map_courselabel'

    id = db.Column(db.String(64), primary_key=True)
    courseid = db.Column(db.String(64), db.ForeignKey('course.id'))
    labelid = db.Column(db.String(64), db.ForeignKey('label.id'))
    createtime = db.Column(db.DateTime)
    flag = db.Column(db.Integer, default=elineStat.examine)
    teahoption = db.Column(db.Integer)
    adminoption = db.Column(db.Integer)
    oldID = db.Column(db.String(64), default=None)


# 案例标签对应表
'''
表名 map_compcaselabel
字段：id，主键。char(64)----------主键
    name 案例名称 char(64)
    compcaseid 综合案例id char(64)--------------外键course.id
    labelid 标签id char(64) --------------外键label.id
    createtime 创建时间 datetime
    flag 启用标识 integer 可选范围：elineStat
    teahoption 老师操作 integer 可选范围：eTeachOption
    adminoption 审批操作 integer 可选范围：eAdminOption
    oldID 旧对应关系id
'''


class tMap_CompCaseLabel(db.Model):
    __tablename__ = 'map_compcaselabel'

    id = db.Column(db.String(64), primary_key=True)
    compcaseid = db.Column(db.String(64), db.ForeignKey('compcase.id'))
    labelid = db.Column(db.String(64), db.ForeignKey('label.id'))
    createtime = db.Column(db.DateTime)
    flag = db.Column(db.Integer, default=elineStat.examine)
    teahoption = db.Column(db.Integer)
    adminoption = db.Column(db.Integer)
    oldID = db.Column(db.String(64), default=None)


# 章节模板类型
'''
表名 modeltype
字段：id，主键。char(64)----------主键
    name 模板类型名称 char(64)
    createtime 创建时间 datetime
    modiftime 最后修改时间 datetime
    flag 启用标识 integer 可选范围：elineStat
    teahoption 提交操作 integer 可选范围：eTeachOption
    adminoption 审批操作 integer 可选范围：eAdminOption
    oldID 旧关系对应本表的关系 char(64)
'''
class tModelType(db.Model):
    __tablename__ = 'modeltype'

    id = db.Column(db.String(64), primary_key=True)
    name = db.Column(db.String(64))
    createtime = db.Column(db.DateTime)
    modiftime = db.Column(db.DateTime)
    flag = db.Column(db.Integer, default=elineStat.enable)
    teahoption = db.Column(db.Integer)  # 1：添加，2：删除
    adminoption = db.Column(db.Integer)
    oldID = db.Column(db.String(64), default=None)

    def __repr__(self):
        return '<modeltype %r>' % self.name


# 章节模板表
'''
表名 captionmodel
字段：id，主键。char(64)----------主键
    name 模板名称 char(64)
    disc 模板描述 text
    modelfile 模板文件url char(255)
    modelfile 模板数据集url char(255)
    modeltypeid 模板类型id char(64) --------------------------外键 modeltype.id
    createtime 创建时间 datetime
    modiftime 最后修改时间 datetime
    flag 启用标识 integer 可选范围：elineStat
    teahoption 提交操作 integer 可选范围：eTeachOption
    adminoption 审批操作 integer 可选范围：eAdminOption
    oldID 旧关系对应本表的关系 char(64)
'''
class tCaptionmodel(db.Model):
    __tablename__ = 'captionmodel'

    id = db.Column(db.String(64), primary_key=True)
    name = db.Column(db.String(128))
    disc = db.Column(db.TEXT)
    modelfile = db.Column(db.String(255))
    modeldata = db.Column(db.String(255))
    modeltype = db.Column(db.String(64), db.ForeignKey('modeltype.id'))
    createtime = db.Column(db.DateTime)
    modeftime = db.Column(db.DateTime)
    flag = db.Column(db.Integer, default=elineStat.examine)
    teahoption = db.Column(db.Integer)  # 1：添加，2：删除
    adminoption = db.Column(db.Integer)
    oldID = db.Column(db.String(64), default=None)

# 学习记录
'''
表名 courselog
字段：id，主键。char(64)----------主键
    studid 学生id char(64) ---------------外键 alluser.id
    teachid 老师id char(64) ---------------外键 alluser.id
    startime 开始时间 datetime
    endtime 结束时间 datetime
    captionmodeid 模板id char(64) ---------------外键 captionmodel.id
    copyfile 副本文件url char(255)
    copydata 副本数据集url char(255)
    flag 启用标识 integer 可选范围：elineStat
'''
class tCourselog(db.Model):
    __tablename__ = 'courselog'

    id = db.Column(db.String(64), primary_key=True)
    studid = db.Column(db.String(64), db.ForeignKey('alluser.id'))
    teacherid = db.Column(db.String(64), db.ForeignKey('alluser.id'))
    startime = db.Column(db.DateTime)
    endtime = db.Column(db.DateTime)
    captionmodeid = db.Column(db.String(64), db.ForeignKey('captionmodel.id'))
    copyefile = db.Column(db.String(255))
    copydata = db.Column(db.String(255))
    flag = db.Column(db.Integer, default=elineStat.enable)  # 1:启用，0：禁用，2，待审核

    def __repr__(self):
        return '<courselog %r>' % self.id


# 老师班级课程对应关系表
'''
表名 map_teachcourseclazz
字段：id，主键。char(64)----------主键
    teachid 老师id char(64) ---------------外键 alluser.id
    courseid 课程id char(64) ---------------外键 course.id
    clazzid 班级id char(64) ---------------外键 clazz.id
    flag 启用标识 integer 可选范围：elineStat
'''
class tMap_teachCourseClazz(db.Model):
    __tablename__ = 'map_teachcourseclazz'

    id = db.Column(db.String(64), primary_key=True)

    teachid = db.Column(db.String(64), db.ForeignKey('alluser.id'))
    courseid = db.Column(db.String(64), db.ForeignKey('course.id'))
    clazzid = db.Column(db.String(64), db.ForeignKey('clazz.id'))
    flag = db.Column(db.Integer, default=elineStat.enable)
    oldid = db.Column(db.String(64), default=None)

    def __repr__(self):
        return '<map_teachcourseclazz %r>' % self.id



# 比赛记录
'''
表名 matchlog
字段：id，主键。char(64)----------主键
    matchid 比赛id char(64) ---------------外键 match.id
    studid  学生id char(64) ---------------外键 alluser.id
    teachid 老师id char(64) ---------------外键 alluser.id
    judgerid 裁判id char(64) ---------------外键 alluser.id
    startime 开始时间 datetime
    endtime 结束时间 datatime
    captionmodelid 模板id -----------------外键 captionmodel.
    copyefile 副本文件url
    copydata 副本数据集url
    sorce 分数
    rank 排名
    flag 启用标识 integer 可选范围：elineStat
'''
class tMatchlog(db.Model):
    __tablename__ = 'matchlog'

    id = db.Column(db.String(64), primary_key=True)
    matchid = db.Column(db.String(64), db.ForeignKey('match.id'))
    studid = db.Column(db.String(64), db.ForeignKey('alluser.id'))
    teacherid = db.Column(db.String(64), db.ForeignKey('alluser.id'))
    judgerid = db.Column(db.String(64), db.ForeignKey('alluser.id'))
    startime = db.Column(db.DateTime)
    endtime = db.Column(db.DateTime)
    captionmodelid = db.Column(db.String(64), db.ForeignKey('captionmodel.id'))
    copyefile = db.Column(db.String(255))
    copydata = db.Column(db.String(255))
    sorce = db.Column(db.Float)
    rank = db.Column(db.Integer)
    flag = db.Column(db.Integer, default=elineStat.enable)  # 1:启用，0：禁用，2，待审核

    def __repr__(self):
        return '<matchlog %r>' % self.id


# 综合联系表
'''
表名 tPracticelog
字段：id，主键。char(64)----------主键
    studid  学生id char(64) ---------------外键 alluser.id
    teachid 老师id char(64) ---------------外键 alluser.id
    startime 开始时间 datetime
    endtime 结束时间 datatime
    captionmodelid 模板id -----------------外键 captionmodel.
    copyefile 副本文件url
    copydata 副本数据集url
    flag 启用标识 integer 可选范围：elineStat
'''
class tPracticelog(db.Model):
    __tablename__ = 'practicelog'

    id = db.Column(db.String(64), primary_key=True)
    studid = db.Column(db.String(64), db.ForeignKey('alluser.id'))
    teacherid = db.Column(db.String(64), db.ForeignKey('alluser.id'))
    startime = db.Column(db.DateTime)
    endtime = db.Column(db.DateTime)
    captionmodeid = db.Column(db.String(64), db.ForeignKey('captionmodel.id'))
    copyfile = db.Column(db.String(255))
    copydata = db.Column(db.String(255))
    flag = db.Column(db.Integer, default=elineStat.enable)  # 1:启用，0：禁用，2，待审核

    def __repr__(self):
        return '<practicelog %r>' % self.id


# 比赛表
'''
表名 tMatch
字段：id，主键。char(64)----------主键
    name 比赛名称
    modelid 模板id char(64)-----------------外键 captnmodel.id
    createteaherid 创建老师id char(64) -----------------外键 alluser.id
    logo 图片url char(255)
    disc 描述
    createtime 创建时间 datetime
    signtime 报名戒指时间 datetime
    startime 开始时间 datetime
    endtime 结束时间 datatime
    studcount 参赛人数 datetime
    judgercount 裁判人数 integer
    flag 启用标识 integer 可选范围：elineStat
    teahoption 提交操作 integer 可选范围：eTeachOption
    adminoption 审批操作 integer 可选范围：eAdminOption
    oldID 旧关系对应本表的关系 char(64)
'''
class tMatch(db.Model):
    __tablename__ = 'match'

    id = db.Column(db.String(64), primary_key=True)
    name = db.Column(db.String(64))
    modelid = db.Column(db.String(64), db.ForeignKey('captionmodel.id'))
    createteacherid = db.Column(db.String(64), db.ForeignKey('alluser.id'))
    logo = db.Column(db.String(255))
    disc = db.Column(db.Text)
    signtime = db.Column(db.DateTime)
    createtime = db.Column(db.DateTime)
    startime = db.Column(db.DateTime)
    endtime = db.Column(db.DateTime)
    studcount = db.Column(db.Integer)
    judgercount = db.Column(db.Integer)
    flag = db.Column(db.Integer, default=elineStat.examine)  # 1:启用，0：禁用，2，待审核
    teahoption = db.Column(db.Integer)  # 1：添加，2：删除
    adminoption = db.Column(db.Integer)
    oldID = db.Column(db.String(64), default=None)

    # players = db.relationship('player', backref='playersinmatch')
    # judgers = db.relationship('judger', backref='judgersinmatch')

    def __repr__(self):
        return '<match %r>' % self.name


# 参赛选手表
'''
表名 player
字段：id，主键。char(64)----------主键
    matchid 比赛id char(64) ------------------外键 match.id
    alluserid 模板id char(64)-----------------外键 alluser.id
    createtime 创建时间 datetime
    flag 启用标识 integer 可选范围：elineStat
'''
class tPlayer(db.Model):
    __tablename__ = 'player'

    id = db.Column(db.String(64), primary_key=True)
    matchid = db.Column(db.String(64), db.ForeignKey('match.id'))
    alluserid = db.Column(db.String(64), db.ForeignKey('alluser.id'))
    createtime = db.Column(db.DateTime)
    flag = db.Column(db.Integer, default=elineStat.examine)  # 1:启用，0：禁用，2，待审核

    def __repr__(self):
        return '<player %r>' % self.id


# 评委表
'''
表名 judger
字段：id，主键。char(64)----------主键
    matchid 比赛id char(64) ------------------外键 match.id
    alluserid 模板id char(64)-----------------外键 alluser.id
    createtime 创建时间 datetime
    flag 启用标识 integer 可选范围：elineStat
'''
class tJudger(db.Model):
    __tablename__ = 'judger'

    id = db.Column(db.String(64), primary_key=True)
    matchid = db.Column(db.String(64), db.ForeignKey('match.id'))
    alluserid = db.Column(db.String(64), db.ForeignKey('alluser.id'))
    createtime = db.Column(db.DateTime)
    flag = db.Column(db.Integer, default=elineStat.examine)  # 1:启用，0：禁用，2，待审核

    def __repr__(self):
        return '<judger %r>' % self.id

########################################################################################################################

########################################################################################################################
# 测试表
class testtable(db.Model):
    __tablename__ = 'testtable'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64))

    def __repr__(self):
        return '<testtable %r>' % self.name
